package com.seeyon.apps.kk.manager;

import java.rmi.RemoteException;
import java.util.List;
import java.util.Map;

import org.apache.axis2.AxisFault;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;

import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub.CheckDate;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub.CheckDateResponse;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub.SpecialEquip;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub.SpecialEquipResponse;

/**
 * 测量设备数据抛送
 * @author seeyon
 *
 */
public class CeLiangSheBeiManagerImpl extends BaseManager{

	private static final Log log = LogFactory.getLog(CeLiangSheBeiManagerImpl.class);
	
	private FreemarkFlowManager freemarkFlowManager;
	// NC 接口调用类
	LyAndOAButtServiceStub stub = null;

	public FreemarkFlowManager getFreemarkFlowManager() {
		return freemarkFlowManager;
	}

	public void setFreemarkFlowManager(FreemarkFlowManager freemarkFlowManager) {
		this.freemarkFlowManager = freemarkFlowManager;
	}
	
	/**
	 * 测量设备周期管理申请表 sendTONC 检验周期
	 */
	public void sendTONCInspectionCycle(Map<String,Object> parmas){
		try {
			String sql = this.freemarkFlowManager.fltTemplateIntoString("datasync/zichankapian/SENDTONCSQL/ZC_ZQGL_TONC_SQL.ftl", parmas);
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			stub = new LyAndOAButtServiceStub();
			for (Map<String, Object> map : array) {
				SpecialEquip specialEquip12 = new SpecialEquip();
				specialEquip12.setString("01");  
				specialEquip12.setString1(MapUtils.getString(map, "assetNo"));
				specialEquip12.setString2(MapUtils.getString(map, "assetName"));
				specialEquip12.set_int(1);
				specialEquip12.setInt1(MapUtils.getInteger(map, "time"));
				specialEquip12.setString3(MapUtils.getString(map, "ID"));
				specialEquip12.setString4(MapUtils.getString(map, "type"));
				SpecialEquipResponse rs = stub.specialEquip(specialEquip12);
				log.info("=================测量设备周期管理申请表=====================\n"+rs.get_return());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCInspectionCycle()");
			log.info("=============NC接口调用出错==============\n"+e.getMessage());
		}
	}
	
	/**
	 * 测量设备周期管理调整申请单 sendTONC 调整周期
	 */
	public void sendTONCAdjustCycle(Map<String,Object> parmas){
		try {
			String sql = this.freemarkFlowManager.fltTemplateIntoString("datasync/zichankapian/SENDTONCSQL/ZC_ZQGLTZ_TONC_SQL.ftl", parmas);
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			stub = new LyAndOAButtServiceStub();
			for (Map<String, Object> map : array) {
				CheckDate checkDate0 = new CheckDate();
				checkDate0.setString1(MapUtils.getString(map, "assetNo"));
				checkDate0.setString2(MapUtils.getString(map, "assetName"));
				checkDate0.setString(MapUtils.getString(map, "type"));
				checkDate0.set_int(MapUtils.getInteger(map, "time"));
				checkDate0.setString3(MapUtils.getString(map, "ID"));
				CheckDateResponse rs = stub.checkDate(checkDate0);
				log.info("=================测量设备周期管理调整申请单=====================\n"+rs.get_return());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCAdjustCycle()");
			log.info("=============NC接口调用出错==============\n"+e.getMessage());
		} 
	}
	
	/**
	 * 测量设备退出周检申请表 sendTONC 送检状态
	 */
	public void sendTONCInspectionStatus(Map<String,Object> parmas){
		try {
			String sql = this.freemarkFlowManager.fltTemplateIntoString("datasync/zichankapian/SENDTONCSQL/ZC_TCZJ_TONC_SQL.ftl", parmas);
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			stub = new LyAndOAButtServiceStub();
			for (Map<String, Object> map : array) {
				SpecialEquip specialEquip12 = new SpecialEquip();
				specialEquip12.setString("01");  
				specialEquip12.setString1(MapUtils.getString(map, "assetNo"));
				specialEquip12.setString2(MapUtils.getString(map, "assetName"));
				specialEquip12.set_int(2);
				specialEquip12.setInt1(0);
				specialEquip12.setString3(MapUtils.getString(map, "ID"));
				SpecialEquipResponse rs = stub.specialEquip(specialEquip12);
				log.info("=================测量设备退出周检申请表=====================\n"+rs.get_return());
				// 向NC抛送送检，同时修改底表数据 为 已退检   4219343471385463672
				String updateSql = "UPDATE FORMMAIN_0986 SET FIELD0012 = '4219343471385463672' WHERE FIELD0001 = '"+MapUtils.getString(map, "assetNo")+"'";
				int num = this.jdbcTemplate.update(updateSql);
				log.info("状态更新成功："+num+"条");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCInspectionStatus()");
			log.info("=============NC接口调用出错==============\n"+e.getMessage());
		} 
	}
}
